% Function converts the angle of a servo into 
% ticks send the PWM generator on ATmega8. The
% PWM generator data are sent along with servo
% data in the data structure:
%
% [CLK , PRESCALER]
% [ A  ,     B    ]
%
% where A, B are parameters for linear regression:
%
%	y = Ax + B [ms]
%
% where both A,B has been established by an experiment
% for choosen servo (9g TowerPro).
function ocr1a = s2avr( angle, data, invert )

	clk = data(1,1);
	pre = data(1,2);
	a = data(2,1);
	b = data(2,2);

	if( 1 == invert )
		angle = pi - angle;
	endif

	tm = a * angle + b;

	ocr1a = uint16((clk * tm) / (pre * 1000));
endfunction
